package com.xcity.robot.net.packet.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xcity.robot.net.packet.BinaryPacket;

import naga.x.net.impl.pomelo.PomeloPacket;

public class DefaultBinaryPacket extends PomeloPacket implements BinaryPacket {

	private byte[] ref;
	
	public DefaultBinaryPacket(int serial, byte[] ref) {
		this.serial = serial;
		this.ref = ref;
	}
	
	@Override
	public byte[] toBinary() {
		return ref;
	}
	
	@Override
	public String toString() {
		JSONObject json = new JSONObject(true);
		json.put("id", serial);
		json.put("msg", JSON.parseObject(ref, JSONObject.class));
		return json.toJSONString();
	}

}
